package com.tchy.cloud.controller;

import com.tchy.cloud.entity.ABankEntity;
import com.tchy.cloud.entity.AOrderEntity;
import com.tchy.cloud.entity.AOrdertimeEntity;
import org.apache.log4j.Logger;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.core.common.service.CommonService;
import org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil;
import org.jeecgframework.core.util.MyBeanUtils;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.tag.vo.datatable.SortDirection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 银行卡信息维护
 */
@Controller
@RequestMapping("/orderController")
public class AOrderController {
    private static final Logger logger = Logger.getLogger(AOrderController.class.getName());

    @Autowired
    private CommonService commonService;

    /**
     * 订单列表页面跳转
     *
     * @return
     */
    @RequestMapping(params = "index")
    public ModelAndView indexView() {
        return new ModelAndView("clound/order/index");
    }

    /**
     * 订单列表列表展示数据
     *
     * @param orderEntity
     * @param request
     * @param response
     * @param dataGrid
     */
    @RequestMapping(params = "datagrid")
    public void datagrid(AOrderEntity orderEntity, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery(AOrderEntity.class, dataGrid);
        cq.addOrder("orderId", SortDirection.desc);
        cq.add();
        // 查询条件组装
        HqlGenerateUtil.installHql(cq, orderEntity, request.getParameterMap());
        commonService.getDataGridReturn(cq, true);
        TagUtil.datagrid(response, dataGrid);
    }


    /**
     * 订单详情查看
     *
     * @param orderEntity
     * @param req
     * @return
     */
    @RequestMapping(params = "detail")
    public ModelAndView detail(AOrderEntity orderEntity, HttpServletRequest req) {
        String id = req.getParameter("id");
        if (id != null) {
            orderEntity = commonService.getEntity(AOrderEntity.class, Long.valueOf(id));
        }
        req.setAttribute("orderEntity", orderEntity);
        List<AOrdertimeEntity> list = commonService.findByProperty(AOrdertimeEntity.class,"orderId",orderEntity.getOrderId());
        req.setAttribute("ordertime", list);
        return new ModelAndView("clound/order/detail");
    }
//
//
//    /**
//     * 新增及修改的数据处理
//     * @param aBankEntity
//     * @return
//     */
//    @RequestMapping(params = "saveorupdate", method = RequestMethod.POST)
//    @ResponseBody
//    public AjaxJson saveorupdate(ABankEntity aBankEntity) {
//        AjaxJson j = new AjaxJson();
//        try {
//            if (aBankEntity.getId() != null) {//修改
//                ABankEntity entity = commonService.get(ABankEntity.class, aBankEntity.getId());
//                MyBeanUtils.copyBeanNotNull2Bean(aBankEntity, entity);
//                commonService.saveOrUpdate(entity);
//            } else {//保存
//                commonService.save(aBankEntity);
//            }
//            j.setMsg("操作成功");
//        } catch (Exception e) {
//            logger.error(e);
//            j.setMsg("操作失败");
//        }
//        return j;
//    }

}







